//
//  VRUser.m
//  VRFirefighting
//
//  Created by Veer on 2018/8/10.
//  Copyright © 2018年 Veer. All rights reserved.
//

#import "VRUser.h"

@implementation VRUser


@synthesize token = _token;
@synthesize mobile = _mobile;
@synthesize CustomerName = _CustomerName;
@synthesize fIsAreaManage = _fIsAreaManage;

+ (instancetype)shareUser
{
    static VRUser *singleton = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        singleton = [[self alloc] init];
    });
    return singleton;
}

- (void)setToken:(NSString *)token
{
    _token = token;
    
    if (token.length > 0) {
        [[NSUserDefaults standardUserDefaults] setObject:token forKey:@"JKToken"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }else{
        [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"JKToken"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
    
}

- (NSString *)token
{
    if (_token) {
        return _token;
    }
    
    _token = [[NSUserDefaults standardUserDefaults] stringForKey:@"JKToken"];
    return _token;
}



- (void)setMobile:(NSString *)mobile
{
    _mobile = mobile;
    
    if (mobile.length > 0) {
        [[NSUserDefaults standardUserDefaults] setObject:mobile forKey:@"JKMobile"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }else{
        [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"JKMobile"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
}

- (NSString *)mobile
{
    if (_mobile.length > 0) {
        return _mobile;
    }
    
    _mobile = [[NSUserDefaults standardUserDefaults] stringForKey:@"JKMobile"];
    return _mobile;
}


- (void)setCustomerName:(NSString *)CustomerName
{
    _CustomerName = CustomerName;
    
    if (CustomerName.length > 0) {
        [[NSUserDefaults standardUserDefaults] setObject:CustomerName forKey:@"CustomerName"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }else{
        [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"CustomerName"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
}

- (NSString *)CustomerName
{
    if (_CustomerName.length > 0) {
        return _CustomerName;
    }
    
    _CustomerName = [[NSUserDefaults standardUserDefaults] stringForKey:@"CustomerName"];
    return _CustomerName;
}


- (void)setFIsAreaManage:(NSInteger)fIsAreaManage
{
    _fIsAreaManage = fIsAreaManage;
    
    if (fIsAreaManage > 0) {
        [[NSUserDefaults standardUserDefaults] setObject:@(fIsAreaManage) forKey:@"fIsAreaManage"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }else{
        [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"fIsAreaManage"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
}

- (NSInteger)fIsAreaManage
{
    if (_fIsAreaManage > 0) {
        return _fIsAreaManage;
    }
    
    _fIsAreaManage = [[NSUserDefaults standardUserDefaults] integerForKey:@"fIsAreaManage"];
    return _fIsAreaManage;
}


- (void)clearInfo
{
    self.token = nil;
    self.CustomerName = nil;
//    self.mobile = nil;
    self.fIsAreaManage = 0;
    self.isLogined = NO;
}

@end
